package com.sz.admin.vehicleinfo.controller;

import com.sz.admin.vehicleinfo.pojo.po.VehicleInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import com.sz.core.common.entity.ApiPageResult;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.common.constant.GlobalConstant;
import com.sz.core.common.entity.PageResult;
import com.sz.core.common.entity.SelectIdsDTO;
import com.sz.admin.vehicleinfo.service.VehicleInfoService;
import com.sz.admin.vehicleinfo.pojo.dto.VehicleInfoCreateDTO;
import com.sz.admin.vehicleinfo.pojo.dto.VehicleInfoUpdateDTO;
import com.sz.admin.vehicleinfo.pojo.dto.VehicleInfoListDTO;
import com.sz.admin.vehicleinfo.pojo.vo.VehicleInfoVO;
import com.sz.core.common.entity.ImportExcelDTO;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * <p>
 * 车辆管理 Controller
 * </p>
 *
 * @author sz-admin
 * @since 2025-08-29
 */
@Tag(name =  "车辆管理")
@RestController
@RequestMapping("vehicle-info")
@RequiredArgsConstructor
public class VehicleInfoController  {

    private final VehicleInfoService vehicleInfoService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "vehicle.info.create", orRole = GlobalConstant.SUPER_ROLE)
    @PostMapping
    public ApiResult<Void> create(@RequestBody VehicleInfoCreateDTO dto) {
        vehicleInfoService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "vehicle.info.update", orRole = GlobalConstant.SUPER_ROLE)
    @PutMapping
    public ApiResult<Void> update(@RequestBody VehicleInfoUpdateDTO dto) {
        vehicleInfoService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @SaCheckPermission(value = "vehicle.info.remove", orRole = GlobalConstant.SUPER_ROLE)
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        vehicleInfoService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "vehicle.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping
    public ApiResult<PageResult<VehicleInfoVO>> list(VehicleInfoListDTO dto) {
        return ApiPageResult.success(vehicleInfoService.page(dto));
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "vehicle.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/{id}")
    public ApiResult<VehicleInfoVO> detail(@PathVariable Object id) {
        return ApiResult.success(vehicleInfoService.detail(id));
    }

    @Operation(summary = "导入")
    @Parameters({
      @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "vehicle.info.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        vehicleInfoService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "vehicle.info.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody VehicleInfoListDTO dto, HttpServletResponse response) {
        vehicleInfoService.exportExcel(dto, response);
    }
    @GetMapping("/test")
    public ApiResult<String> test() {
        return ApiResult.success("test");
    }
    /**
     * 获取车辆详细信息
     */
    @GetMapping("/test2/{id}")
    @Operation(summary = "根据ID获取车辆及部门信息")
    public ApiResult<VehicleInfoVO> getVehicleInfo(@PathVariable Long id) {
        VehicleInfoVO vehicleInfovo = vehicleInfoService.getVehicleWithDeptById(id);
        return ApiResult.success(vehicleInfovo);
    }

    @Operation(summary = "不分页列表查询")
    @GetMapping("/listNop")
    public ApiResult<List<VehicleInfoVO>> listNop(VehicleInfoListDTO dto) {
        return ApiResult.success(vehicleInfoService.list(dto));
    }
}